package com.xu.use;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat;

import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.llx.use.Keyboard;
import com.llx.use.Logger;
import com.llx.use.Threads;
import com.llx.use.Use;
import com.llx.use.Viewer;
import com.llx.use.thread.Run;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Use.init(this);
        setContentView(R.layout.activity_main);


        TextView textView = findViewById(R.id.content);
        Keyboard keyboard = findViewById(R.id.keyboard);
        keyboard.setOnEventListener(text -> {
            textView.setText(text);
        });
        keyboard.setMaxNumberWidth(600);
        keyboard.setFontSize(20);
        keyboard.setKeyColor(Color.BLUE);
        keyboard.setKeyPressColor(Color.GREEN);

        textView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (Viewer.isVisible(keyboard)) {
                    Viewer.hide(keyboard);
                } else Viewer.show(keyboard);
            }
        });

        //LogWindow.open(this);

        Run run = new Run() {
            @Override
            public void run() {
                super.run();
                Logger.e("开始");
                Threads.sleep(5000);
                Logger.e(interrupted());
                Logger.e("结束");
            }
        };

        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                Logger.e("执行Runnable");
            }
        };

        Threads.back(runnable, 5000);

        Threads.io(run);

        Threads.ui(() -> {
            Threads.remove(run);
            Logger.e("取消");
        }, 2000);

        Threads.ui(() -> {
            //Logger.e("5秒到");
        }, 5000);
    }
}